package com.ymatou.iapi.auth.testcase;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.auth.parameter.UserTokenDtoBean;
import com.ymatou.iapi.auth.service.UserTokenDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 创建获取token FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_UserTokenDto {
	private static UserTokenDtoBean usertokendtoBean;
	private static UserTokenDtoCall usertokendtoCall;
	private UserTokenWapper userTokenWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建获取token");
	}

	@Before
	public void caseUp() throws Exception {
		usertokendtoBean = new UserTokenDtoBean();
		usertokendtoCall = new UserTokenDtoCall();
		userTokenWapper = new UserTokenWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(usertokendtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Ts_UserTokenDto_001() {
		Logger.start(true, "用户存在token,创建token,创建token");
		try {
			UserRegisterInfoRequestDtoBean cur = new UserRegisterInfoRequestDtoBean();
			cur = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(cur);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			int UserId = registerResult.get("UserId").getAsInt();
			String AccessToken = registerResult.get("Token").getAsString();
			usertokendtoBean.setUserId(UserId);
			usertokendtoBean.setTokenSource(cur.getChannelSource().toString());
			usertokendtoBean.setContext("login");
			usertokendtoBean.setClientIp(cur.getClientIp());
			usertokendtoBean.setDeviceId("uryuoewhr");
			usertokendtoBean.setTokenTimeOut(cur.getTokenTimeOut());
			usertokendtoBean.setAppId("auth.iapi.ymatou.com");
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();
			Logger.verifyEquals(false, usertokendtoCall.getResult().equals(AccessToken), "验证两个token是否一致");
			usertokendtoCall.callService();
			
			Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
			Logger.verifyEquals(false, usertokendtoCall.getResult().equals(AccessToken), "验证两个token是否一致");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Ts_UserTokenDto_002() {
		Logger.start(true, "用户不存在token,创建token");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);

			usertokendtoBean.setUserId(uid);
			usertokendtoBean.setTokenSource(cur.getChannelSource().toString());
			usertokendtoBean.setContext("login");
			usertokendtoBean.setClientIp(cur.getClientIp());
			usertokendtoBean.setDeviceId("uryuoewhr");
			usertokendtoBean.setTokenTimeOut(1L);
			usertokendtoBean.setAppId("auth.iapi.ymatou.com");
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();

			Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
			Thread.sleep(1000);
			Map<String, Object> userlst = userTokenWapper.getUserTokenByUid(uid);
			Logger.debug(userlst);
			if (userlst != null && userlst.size() > 0)
				Logger.verifyEquals(userlst.get("sId"), usertokendtoCall.getResult(), "验证Result");
			else
				Logger.verifyEquals("", usertokendtoCall.getResult(), "验证Result");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Ts_UserTokenDto_003() {
		Logger.start(true, "用户不存在token,创建token,渠道wxapp");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);

			usertokendtoBean.setUserId(uid);
			usertokendtoBean.setTokenSource("WxApp");
			usertokendtoBean.setContext("login");
			usertokendtoBean.setClientIp(cur.getClientIp());
			usertokendtoBean.setDeviceId("uryuoewhr");
			usertokendtoBean.setTokenTimeOut(1L);
			usertokendtoBean.setAppId("auth.iapi.ymatou.com");
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();

			Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
			Thread.sleep(1000);
			Map<String, Object> userlst = userTokenWapper.getUserTokenByUid(uid);
			Logger.debug(userlst);
			if (userlst != null && userlst.size() > 0) {
				Logger.verifyEquals(usertokendtoCall.getResult(), userlst.get("sId"), "验证Result");
				Logger.verifyEquals("wxapp", userlst.get("tSource"), "验证tSource");
				Logger.verifyEquals(uid, userlst.get("uId"), "验证uId");
			} else
				Logger.verifyEquals("", usertokendtoCall.getResult(), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Ts_UserTokenDto_004() {
		Logger.start(true, "不传userid");
		try {
			usertokendtoBean.setTokenSource("WxApp");
			usertokendtoBean.setContext("login");
			usertokendtoBean.setDeviceId("uryuoewhr");
			usertokendtoBean.setAppId("auth.iapi.ymatou.com");
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();
			Logger.verifyEquals("100", usertokendtoCall.getString("Code"), "验证Code");
			Logger.verifyEquals(false, usertokendtoCall.getResult()==null, "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_005() {
	 Logger.start(false,"创建token,設置過期時間");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenSource("WxApp");
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setDeviceId("suibianchuangde");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
		 Logger.verifyEquals(usertokendtoBean.getTokenSource().toLowerCase(), userToken.get(0).get("tSource"), "验证tSource");
		 Logger.verifyEquals(usertokendtoBean.getDeviceId(), userToken.get(0).get("deviceId"), "验证deviceId");
		 Date etime = (Date)userToken.get(0).get("eTime");
		 Date ctime = (Date)userToken.get(0).get("cTime");
		 Long date = castDate(etime,ctime);
		 Logger.verifyEquals(usertokendtoBean.getTokenTimeOut(), date, "验证过期时间");
		
	 } catch (Exception e) {
	 Logger.fail(e);
	 }
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_006() {
	 Logger.start(false,"创建token,再次创建token,都有DeviceId，deviceId一致");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenSource("WxApp");
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setDeviceId("suibianchuangde");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setTokenSource("GlobleWxApp");
		 usertokendtoBean.setDeviceId("suibianchuangde");
		 usertokendtoBean.setUserId(uid);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(2, userToken.size(), "验证2条记录");
		 Logger.debug("userToken:"+userToken);
		 Map mgw=userToken.stream().filter(m->m.get("tSource").equals("globlewxapp")).findFirst().get();
		 Logger.verifyEquals(usertokendtoCall.getResult(), mgw.get("sId"), "验证token");
		 Logger.verifyEquals(usertokendtoBean.getTokenSource().toLowerCase(), mgw.get("tSource"), "验证tSource");
		 Logger.verifyEquals(usertokendtoBean.getDeviceId(), mgw.get("deviceId"), "验证deviceId");
		 Date etime = (Date)mgw.get("eTime");
		 Date ctime = (Date)mgw.get("cTime");
		 Long date = castDate(etime,ctime);
		 Logger.verifyEquals(usertokendtoBean.getTokenTimeOut(), date, "验证过期时间");
		
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_007() {
	 Logger.start(false,"创建token,再次创建token,前后DeviceId不一致");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenSource("WxApp");
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setDeviceId("suibianchuangde");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setDeviceId("sjhw");
		 usertokendtoBean.setUserId(uid);
		 usertokendtoCall.callService();
		 
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 //deviceId值不同，会重新创建一个token，保留原来的token
		 Logger.verifyEquals(true, userToken.size() == 2, "验证token有两个值");
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_008() {
	 Logger.start(false,"创建token,再次创建token,开始无DeviceId，后来有DeviceId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setDeviceId("suibianchuangde");
		 usertokendtoBean.setUserId(uid);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 //deviceId值不同，会重新创建一个token，保留原来的token
		 Logger.verifyEquals(true, userToken.size() == 2, "验证token有两个值");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_009() {
	 Logger.start(false,"创建token,再次创建token,开始有DeviceId，后来无DeviceId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoBean.setDeviceId("suibianchuangde");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 UserTokenDtoBean userTokenDtoBean2 = new UserTokenDtoBean();
		 userTokenDtoBean2.setUserId(uid);
		 userTokenDtoBean2.setTokenTimeOut(1L);
		 userTokenDtoBean2.setContext("reg");
		 userTokenDtoBean2.setClientIp("173.937.23.213");
		 usertokendtoCall.setData(userTokenDtoBean2);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 //deviceId值不同，会重新创建一个token，保留原来的token
		 Logger.verifyEquals(true, userToken.size() == 2, "验证token有两个值");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_010() {
	 Logger.start(false,"创建token,再次创建token,都无DeviceId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setUserId(uid);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 //不传deviceId，会创建两个token
		 Logger.verifyEquals(true, userToken.size() == 2, "验证token有两个值");
		
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_011() {
	 Logger.start(false,"创建token,无认证渠道信息，有deviceId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoBean.setDeviceId("dasfdas");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_012() {
	 Logger.start(false,"创建token,设置过期时间,无认证渠道，无deviceId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setClientIp("173.937.23.213");
		 usertokendtoBean.setTokenTimeOut(2L);
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_013() {
	 Logger.start(false,"创建token,设置过期时间，过期时间为负数,无认证渠道，无deviceId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setContext("reg");
		 usertokendtoBean.setClientIp("173.217.653.54");
		 usertokendtoBean.setTokenTimeOut(-2L);
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_014() {
	 Logger.start(false,"创建token,只传userId");
	 try {
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_015() {
	 Logger.start(false,"创建token,ClientIp格式不正确");
	 try {
		 //不进入数据库
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setContext("reg");
		 
		 usertokendtoBean.setClientIp("173.937.23.wdyg");
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_016() {
	 Logger.start(false,"创建token,过期时间设置超大上线");
	 try {
		 //按默认一个月处理
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setContext("reg");
		 
		 usertokendtoBean.setClientIp("173.937.23.34");
		 usertokendtoBean.setTokenTimeOut(1000000000000000000L);
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
	 
	 @Test
	 @Category({P3.class})
	 @TestCase
	 public void Ts_UserTokenDto_017() {
	 Logger.start(false,"创建token,多个渠道同时登录");
	 try {
		 //按默认一个月处理
		 CreateUserReq cur = new CreateUserReq();
		 cur = JUserCallService.initCreateUserBean(cur);
		 int uid = JUserCallService.createUserCall(cur);
		 usertokendtoBean.setUserId(uid);
		 usertokendtoBean.setContext("login");
		 
		 usertokendtoBean.setTokenSource("Pc");
		 usertokendtoBean.setDeviceId("gydasjg");
		 usertokendtoBean.setTokenTimeOut(1L);
		 usertokendtoBean.setClientIp("173.937.23.34");
		 usertokendtoCall.setData(usertokendtoBean);
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setTokenSource("WxApp");
		 usertokendtoBean.setDeviceId("siahf");
		 usertokendtoBean.setClientIp("174.937.23.34");
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setTokenSource("App");
		 usertokendtoBean.setDeviceId("shduh");
		 usertokendtoBean.setClientIp("174.93.23.34");
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setTokenSource("SellerApp");
		 usertokendtoBean.setDeviceId("fhfuhu");
		 usertokendtoBean.setClientIp("174.53.23.34");
		 usertokendtoCall.callService();
		 
		 usertokendtoBean.setTokenSource("App");
		 usertokendtoBean.setDeviceId("shduh");
		 usertokendtoBean.setClientIp("174.93.23.34");
		 usertokendtoCall.callService();
		 
		 Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
		 Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
		 List<Map> userToken = getUserToken(usertokendtoBean, uid);
		 Logger.debug(userToken);
		 Logger.verifyEquals(4, userToken.size(), "验证渠道");
//		 Map mgw=userToken.stream().filter(m->m.get("tSource").equals("App")).findFirst().get();
		 Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(3).get("sId"), "验证token");
	 	} catch (Exception e) {
	 		Logger.fail(e);
	 	}
	 }
//	    GodSellerWxApp(62, "GodSellerWxApp"),
//	    GodSellerPc(63, "GodSellerPc"),
//	    GodSellerApp(64, "GodSellerApp");
//
//	token.expireInterval.godSellerPc=24
//	token.expireInterval.godSellerApp=720
//	token.expireInterval.godSellerWxApp=720
	@Test
	@Category({ P3.class })
	@TestCase
	public void Ts_UserTokenDto_018() {
		Logger.start(false, "创建token,设置过期时间-GodSellerWxApp");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			usertokendtoBean.setUserId(uid);
			usertokendtoBean.setTokenSource("GodSellerWxApp");
			// usertokendtoBean.setTokenTimeOut(1L);
			usertokendtoBean.setContext("reg");
			usertokendtoBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			usertokendtoBean.setClientIp(TestDataManager.getRandomIp());
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();
			List<Map> userToken = getUserToken(usertokendtoBean, uid);
			Logger.debug("userToken:" + FormatUtil.beanToGSONString(userToken));
			Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
			Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
			Logger.verifyEquals(usertokendtoBean.getTokenSource().toLowerCase(), userToken.get(0).get("tSource"), "验证tSource");
			Logger.verifyEquals(usertokendtoBean.getDeviceId(), userToken.get(0).get("deviceId"), "验证deviceId");
			Date etime = (Date) userToken.get(0).get("eTime");
			Date ctime = (Date) userToken.get(0).get("cTime");
			//30天
			Logger.verifyEquals(30 * 24 * 60 * 60 * 1000l, etime.getTime() - ctime.getTime(), "验证过期时间");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P3.class })
	@TestCase
	public void Ts_UserTokenDto_019() {
		Logger.start(false, "创建token,设置过期时间-godSellerPc");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			usertokendtoBean.setUserId(uid);
			usertokendtoBean.setTokenSource("godSellerPc");
			// usertokendtoBean.setTokenTimeOut(1L);
			usertokendtoBean.setContext("reg");
			usertokendtoBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			usertokendtoBean.setClientIp(TestDataManager.getRandomIp());
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();
			List<Map> userToken = getUserToken(usertokendtoBean, uid);
			Logger.debug("userToken:" + FormatUtil.beanToGSONString(userToken));
			Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
			Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
			Logger.verifyEquals(usertokendtoBean.getTokenSource().toLowerCase(), userToken.get(0).get("tSource"), "验证tSource");
			Logger.verifyEquals(usertokendtoBean.getDeviceId(), userToken.get(0).get("deviceId"), "验证deviceId");
			Date etime = (Date) userToken.get(0).get("eTime");
			Date ctime = (Date) userToken.get(0).get("cTime");
			//1天
			Logger.verifyEquals(1 * 24 * 60 * 60 * 1000l, etime.getTime() - ctime.getTime(), "验证过期时间");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P3.class })
	@TestCase
	public void Ts_UserTokenDto_020() {
		Logger.start(false, "创建token,设置过期时间-GodSellerApp");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			usertokendtoBean.setUserId(uid);
			usertokendtoBean.setTokenSource("GodSellerApp");
			// usertokendtoBean.setTokenTimeOut(1L);
			usertokendtoBean.setContext("reg");
			usertokendtoBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			usertokendtoBean.setClientIp(TestDataManager.getRandomIp());
			usertokendtoCall.setData(usertokendtoBean);
			usertokendtoCall.callService();
			List<Map> userToken = getUserToken(usertokendtoBean, uid);
			Logger.debug("userToken:" + FormatUtil.beanToGSONString(userToken));
			Logger.verifyEquals(true, usertokendtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, usertokendtoCall.getCode(), "验证Code");
			Logger.verifyEquals(usertokendtoCall.getResult(), userToken.get(0).get("sId"), "验证token");
			Logger.verifyEquals(usertokendtoBean.getTokenSource().toLowerCase(), userToken.get(0).get("tSource"), "验证tSource");
			Logger.verifyEquals(usertokendtoBean.getDeviceId(), userToken.get(0).get("deviceId"), "验证deviceId");
			Date etime = (Date) userToken.get(0).get("eTime");
			Date ctime = (Date) userToken.get(0).get("cTime");
			//30天
			Logger.verifyEquals(30 * 24 * 60 * 60 * 1000l, etime.getTime() - ctime.getTime(), "验证过期时间");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	 public List<Map> getUserToken(UserTokenDtoBean usertokendtoBean,Integer userId) throws Exception{
		 List<Map> userTokenByUserId = userTokenWapper.getUserTokenByUserId(userId);
		 return userTokenByUserId;
	 }
	 public Long castDate(Date date1,Date date2) throws ParseException{
		 SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
		 long nd = 1000 * 24 * 60 * 60;
		 long nh = 1000 * 60 * 60;
		 Date d1 = sdf.parse(date1.toString());
		 Date d2 = sdf.parse(date2.toString());
//		 Logger.debug("d1:"+d1);
//		 Logger.debug("d2:"+d2);
		 long time1 = d1.getTime();
		 long time2 = d2.getTime();
		 long diff = time1 - time2;
		 return diff % nd / nh; 
		 
	 }
}